package com.lgx.common.web.json;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

/**
 * converse object to json
 * converse json to object
 * @author pengdeyi (king)
 *
 * @param <T>
 */
public class JsonUtils {
	
	private static final Gson gson = new Gson();
	
	/**
	 * this converse object to json data.
	 * @return
	 * @throws Exception
	 */
	public String converToJson(Object t){
		return gson.toJson(t);
	}
	
	/**
	 * this converse json to object
	 * @param clazz
	 * @param json
	 * @return
	 */
	public Object converToJson(String json){
		return gson.fromJson(json, new TypeToken<Object>(){}.getType());
	}
	
}
